﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PaintDotNetForms
{
    public partial class FrmNewSize : Form
    {
        private Size size;

        public Size PnlSize
        {
            get { return size; }
            set
            {
                size = value;
                txtWidth.Text = size.Width.ToString();
                txtHeight.Text = size.Height.ToString(); size = value;
            }
        }

        public FrmNewSize()
        {
            InitializeComponent();
        }

        private bool IsInt(string txt)
        {
            try
            {
                int.Parse(txt);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if(!IsInt(txtHeight.Text))
            {
                errorProvider1.SetError(txtHeight,"Enter height");
                return;
            }
            if (!IsInt(txtWidth.Text))
            {
                errorProvider1.SetError(txtWidth, "Enter width");
                return;
            }

            size = new Size(int.Parse(txtWidth.Text),int.Parse(txtHeight.Text));
            DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}